package com.lzb.musicplayer.activity;

import android.content.Intent;
import android.os.Build;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.lzb.musicplayer.BaseAc;
import com.lzb.musicplayer.R;
import com.lzb.musicplayer.databinding.ActivityWebBinding;


public class WebActivity extends BaseAc<ActivityWebBinding> {

    @Override
    protected int onCreate() {
        return R.layout.activity_web;
    }

    @Override
    protected void initView() {
        mDataBinding.ivWebBack.setOnClickListener(view -> getOnBackPressedDispatcher().onBackPressed());

        initWebViewAttribute(mDataBinding.webView);

//        AppStatusProcessor.statusEnterPrivacyWebPage(mDataBinding.webView);

        Intent intent = getIntent();
        int type = intent.getIntExtra("type", 0);
        if (type == 0) {
            mDataBinding.tvTitle.setText(getString(R.string.user_agreement));
            mDataBinding.webView.loadUrl("www.baidu.com");
        } else {
            mDataBinding.tvTitle.setText(getString(R.string.privacy_policy));
            mDataBinding.webView.loadUrl("www.baidu.com");
        }
    }

    @Override
    protected void initData() {

    }

    public void initWebViewAttribute(WebView webview) {
        webview.requestFocus();

        WebSettings webSettings = webview.getSettings();
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDefaultTextEncodingName("UTF-8");
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        webSettings.setLightTouchEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setBlockNetworkImage(false);
        webSettings.setLoadWithOverviewMode(true);
        if (Build.VERSION.SDK_INT >= 15) {
            webSettings.setAllowUniversalAccessFromFileURLs(true);
            webSettings.setAllowFileAccessFromFileURLs(true);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webSettings.setMixedContentMode(0);
        }

        webSettings.setAllowFileAccess(true);
        webSettings.setAllowContentAccess(true);

        webview.setWebViewClient(new WebViewClient());
    }
}